/*
 * Copyright (C) 2000-2004 Technical University of Ilmenau, Germany
 *                         Department of Electronic Circuits & Systems
 *
 * You may only use this file according to the terms of the license agreement included
 * within the file LICENSE which is distributed together with the software package.
 *
 * CVS Info:
 * $Author: rummler $
 * $Date: 2004/03/10 20:19:51 $
 * $Revision: 1.1.2.1 $
 * $State: Exp $
 * $RCSfile: TrivialMutator.java,v $
 *
 */
package elka.isi.operator;

import org.evolvica.core.IIndividual;
import org.evolvica.core.mutate.AbstractMutator;
import org.evolvica.util.RandomUtils;

import elka.isi.RWAlgorithm;
import elka.isi.gene.*;

// a trivial class that mutates strings
public class RWMutator extends AbstractMutator {
	

	// the method that mutates the string
	public int[] mutate( int[] value ) {
		// we simply create a new random string of size 10, not effective, but trivial :-)
//		return RandomStringUtils.randomAlphabetic( 10 );
		for (int i = 0; i < value.length; i++) {
			value[i] += RandomUtils.randomInt(-RWAlgorithm.MUTATION_RANGE, RWAlgorithm.MUTATION_RANGE);
			if(value[i]> RWAlgorithm.MAX_PARAMETER)
				value[i] = RWAlgorithm.MAX_PARAMETER;
			else if(value[i] < RWAlgorithm.MIN_PARAMETER)
				value[i] = RWAlgorithm.MIN_PARAMETER;
		}
		return value;
	}

	/* (non-Javadoc)
	 * @see org.evolvica.core.mutate.AbstractMutator#mutate(org.evolvica.core.IIndividual)
	 */
	public void mutate(IIndividual ind) {
		AnimalGene gene = (AnimalGene) ind.getGenotype();
		gene.setValue( mutate( gene.getValue() ) );
		
	}

}
